package com.chinastock.serializer;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

/**
 * @author zhangfan.it
 * @date 2021/2/4
 */
@Configuration
public class FastJsonSerializer implements WebFluxConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/swagger-ui.html**")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Override
    public void configureHttpMessageCodecs(ServerCodecConfigurer configure) {
        // TODO Auto-generated method stub
        WebFluxConfigurer.super.configureHttpMessageCodecs(configure);
        configure.defaultCodecs().jackson2JsonEncoder(new JsonEncoder());
        configure.defaultCodecs().jackson2JsonDecoder(new JsonDecoder());
    }
}
